package health.lm.com.find.adapter;

import android.support.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import health.lm.com.component_base.helper.ImageLoaderHelper;
import health.lm.com.component_base.widget.RatingBar;
import health.lm.com.find.R;
import health.lm.com.find.entity.EvaluationEntity;

/**
 * 商户评价
 * @author Administrator
 */

public class EvaluationAdapter extends BaseQuickAdapter<EvaluationEntity.Comment_list,BaseViewHolder> {
    public EvaluationAdapter(@Nullable List<EvaluationEntity.Comment_list> data) {
        super(R.layout.item_evaluation, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, EvaluationEntity.Comment_list item) {
        helper.setText(R.id.tv_nickname,item.getMobile())
                .setText(R.id.tv_date,getDate2String(item.getComment_time(),"yyyy-MM-dd HH:mm:ss"))
                .setText(R.id.tv_content,item.getContent());
        ((RatingBar)helper.getView(R.id.rb_start)).setStar(item.getStar());
        if (StringUtils.isEmpty(item.getAvatar())){
            ImageLoaderHelper.getInstance().load(mContext,R.drawable.profile_head_default,helper.getView(R.id.iv_user_head));
        }else {
            ImageLoaderHelper.getInstance().load(mContext,item.getAvatar(),helper.getView(R.id.iv_user_head));
        }
    }
    /**
     *
     * @param time  1541569323155
     * @param pattern yyyy-MM-dd HH:mm:ss
     * @return 2018-11-07 13:42:03
     */
    public static String getDate2String(long time, String pattern) {
        Date date = new Date(time*1000L);
        SimpleDateFormat format = new SimpleDateFormat(pattern, Locale.getDefault());
        return format.format(date);
    }
}
